<template>
	<view class="content">
		<view style="padding-top: 70upx;padding-bottom: 60upx;">
			<view style="font-size: 50upx;">被保人信息注册</view>
		</view>
		<view>
			<input class="input" placeholder="被保人姓名" type="text" v-model="username" />
			<input class="input" password placeholder="证件号码" type="text" v-model="idcard" />
		</view>

		<view class="button">
			<button style="background-color: #51a938; color: #FFFFFF;" @click="register()">注册</button>
			<!-- <view style="font-size:30upx; padding-top: 20upx; color: #808080; text-align: center;" @click="scanIdCard()">扫描身份证</view> -->
			<view style="font-size:30upx; padding-top: 20upx; color: #808080; text-align: center;" @click="adminLogin()">管理员登陆</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
				idcard: ''
			}
		},
		onLoad() {

		},
		methods: {
			register() {
				if (this.username === '' || this.idcard === '') {
					uni.showToast({
						title: '姓名或身份证为空！',
						icon: 'none',
					});
				} else {
					let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
					if (!reg.test(this.idcard)) {
						uni.showToast({
							title: '身份证号格式不对！',
							icon: 'none',
						});
					} else {
						uni.request({
							url: 'register/addUser',
							method: 'POST',
							header: {
								'content-type': 'application/x-www-form-urlencoded',
							},
							data: {
								userName: this.username,
								idCard: this.idcard
							},
							success: function(res) {
								if (res.data == '插入成功！') {
									uni.showToast({
										icon: 'success',
										title: '注册成功！',
										duration: 2000,
										mask: true
									});
									// uni.navigateTo({
									// 	url: '../userinfo/userinfo?username=' + this.userName + '&idcard=' + this.idCard
									// })
								} else {
									uni.showToast({
										title: '注册失败！',
										duration: 2000
									});
								}
							}
						})

						this.username = '',
							this.idcard = ''
					}
				}
			},
			scanIdCard() {
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: function(res) {
						uni.showToast({
							title: "扫描成功！",
						});
					}
				})
			},
			adminLogin() {
				uni.navigateTo({
					url: '../adminLogin/adminLogin'
				})
			}
		}
	}
</script>

<style>
	.input {
		height: 120upx;
		width: 600upx;
		border: 0;
		border-bottom: 2upx solid #C8C7CC;
		background: #FFFFFF;
	}

	.content {
		padding-left: 80upx;
		background: 'url(/static/timg.jpeg)';
	}

	.button {
		width: 600upx;
		padding-top: 60upx;
	}
</style>
